partyGames - Monopoly Functions

Improvements using RcppArmadillo and Open MP

Kline DuBose

Introduction

In order to get practice with the Rcpp::Armadillo package and attempt to implement Open MP into the package, there are three new functions and two new S3 methods that I have added to the package

Explanation

Monopoly is one of my favorite games. After the midterm, I knew I wanted to add a simulation for Monopoly to see which spaces are landed on over multiple games. I also found Open MP to be pretty interesting and wanted to get a chance to understand using it better.

Explanation (pt.2)

The board is based on the 2008 Monopoly board.

Monopoly Board

Explanation (pt. 3)

The Chance and Community Chest cards are also from the 2008 US version of the game.

(a) Chance

(b) Community

Figure 1: List of Community Chest cards and Chance cards used.

New Functions

diceRoll

One of the new functions that was added was a dice rolling function that rolls multiple dice and returns a vector representing the dice that were rolled.

# Two six sided dice
diceRoll(6, 2)
[1] 1 2
# Three 100 sided dice
diceRoll(100, 3)
[1] 93 99 85
# Five six sided dice (like yahtzee)
diceRoll(6, 5)
[1] 2 4 2 2 3

monopoly

This function simulates a single-player version of monopoly to and returns a vector of integers that represents how many times each space was landed on during the game.

monopoly(500, 6, 2)
 [1] 12 14 10 12 14 22 17 13 20  7 21 15 17 17 11 18 12 12 11 14 17 15 16 22  9
[26]  8 12 13 15  8 21 13 17 19 16 10 16 17 13 15
monopoly(500, 20, 2)
 [1] 14  9 12  8 11 19 13 11  8 15 16  8 13 15 17  6  8 25 11 17  7 12 13 14 14
[26] 15 12 17 10 18 14 12 15  9 12 16  9 15 11 13

simulateMonopoly

This function simulates multiple single-player versions of the game and returns a list of class “monopoly” where each entry in the list is a vector representing a single game. This doesn’t parallelize the code like I’m hoping it would and is subject to change.

monoGame <- simulateMonopoly(10, 500, 6, 2, 1)
monoGame
[[1]]
 [1]  6 16 12 17 11 14 20 12 11 14 19 15 16  9 16 17 17  7 15 16 15 15 14 17 22
[26] 14 18 14 12 14 17 11 14 21 17 16 15  9 24 19

[[2]]
 [1] 18 13 11 11 10 19 12 10 13 16 25 16 12 23 13 15 15 18 14 15 13 21 20 12 21
[26] 19 11 10 14 12 17 13 23 20 13  7 17 11 16 15

[[3]]
 [1] 14 14 17 12  8 15 16 21 14 17 12 22 15 15 17 11 12 13  9 18 15 17 12 17 15
[26] 14 20 14  8 18 14  9 13 19 14 17 13 14 18 12

[[4]]
 [1] 18 20  8 20  7 15 15 13 12 19 19 16 18 16 11 11 20 16  9 19 15 14 11 21 14
[26] 12 16 13 16 13 13 12 16 15 17 13 14 14 14 15

[[5]]
 [1] 11 13 11 21  7 17 14 11 13 15 30 14 15 13 18 17 14 19 12 13 17 19 16 16 20
[26]  7 11 13 14 17  9 17 13 15 11 17 10 13 13 14

[[6]]
 [1] 14 14 13 10 10 14 13 15 23 13 19  9 16 12 13 13 15 19 15 11 19 12 15 15 19
[26] 13 13 15 15 16 11 15 14 16 13 16 18 16 21  7

[[7]]
 [1] 14 11 16 12  9 19 10 15 17 17 17  9 17 14 22  9 12 12 16 18 18 16 16 15 10
[26] 16 18 13 10 18 11 11 12 14 20 10 17 12 17 14

[[8]]
 [1]  8 12 12 16 14 12 19 10 13 16 20 16 16 17 13 12 18 13 15  9 22 18 11 18 13
[26] 15 17 12 12 16 11 19 12 13 15 17  9 15 20 14

[[9]]
 [1] 17 17 13 14 12 18 14 18 12 13 23 12 19 16 10 13 12 26 18 13 13 19  9 17 18
[26]  9 14 11 18 16 17 14 11 10 13 18 14 15 17 11

[[10]]
 [1] 10 12 20  8 15 21 17 18  8 15 22 13 12 22 12 14 19 15  8 18 16 16 15 19  9
[26] 20 18  9  9 24  8 17 19 11 15 13 11 10 18 16

attr(,"class")
[1] "monopoly" "list"    

summarize.monopoly

This is the S3 method for monopoly class objects. It returns a numeric vector of class “monoSum” that represents how many times each space was landed on over the coure of the various games.

summary.monopoly(monoGame)
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20 
130 142 133 141 103 164 150 143 136 155 206 142 156 157 145 132 154 158 131 150 
 21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40 
163 167 139 167 161 139 156 124 128 164 128 138 147 154 148 144 138 129 178 137 
attr(,"class")
[1] "monoSum" "numeric"

plot.monopoly

This is the S3 method for monopoly and monoSum class objects. It returns a barplot showing which space was landed on the most.

plot.monopoly(monoGame)

Conclusion

This was a fun chance to learn how OpenMP functions and RcppArmadillo as well. Though the parallelization doesn’t always work, I feel like I have a better understanding the requirements to use OpenMP and other libraries used in C++.

Questions

Sources

For the Cards: https://www.monopolyland.com/list-monopoly-chance-community-chest-cards/

For the Board: https://monopoly.fandom.com/wiki/Monopoly_Board

Special Thanks to George Vega Yon and Jonathan Chipman

See also: https://github.com/UofUEpiBio/PHS7045-advanced-programming/tree/main/projects/04-monopoly-game